home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10235 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  43 lines

  1. Path: news.uregina.ca!usenet
  2. From: tristan@nether.net (Tristan Psionic)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: ?? How to dump text files to screen ??
  5. Date: 16 Mar 1996 03:53:14 GMT
  6. Organization: University of Regina
  7. Message-ID: <4iddva$aic@sue.cc.uregina.ca>
  8. References: <31430CE8.469E@aol2.com>
  9. Reply-To: tristan@nether.net (Tristan Psionic)
  10. NNTP-Posting-Host: dec5057.cs.uregina.ca
  11. X-Newsreader: IBM NewsReader/2 v1.2.5
  12.  
  13. In <31430CE8.469E@aol2.com>, Neil <neil@aol2.com> writes:
  14. >I need help -- how can I open up a text file and just dump it
  15. >all out (in plain text) to the screen?
  16. Well, you can't do exactly that, but this is pretty close (and pretty raw):
  17.  
  18. #include <stdio.h>
  19.  
  20. void main (int argc,char argv[])
  21. {
  22.   FILE *fp;
  23.   char s[1000];
  24.   if (argc >= 1)
  25.   {
  26.     fp=fopen(argv[1],"r");
  27.     while (gets(s,1000,fp) != NULL)
  28.     {
  29.       printf("%s",s);
  30.     }
  31.     fclose(fp);
  32.   }
  33.   else
  34.   {
  35.     printf("usage:  dumptext [filename]"
  36.   }
  37. }
  38.  
  39. That should work.  I'm not an expert at C or anything, but I do believe that
  40. there aren't any hugely flawed errors in it.  Good luck.
  41. -tristan
  42.  
  43.